<?php

declare(strict_types=1);

namespace App\Controller\admin;

use App\Controller\AbstractController;
use App\Model\admin\SystemPermission;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Raw;
use EasyWeChat\Kernel\Messages\Text;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\Utils\ApplicationContext;
use Psr\Http\Message\ResponseInterface;
use Psr\SimpleCache\CacheInterface;


/**
 * @Controller(prefix="admin")
 * Class AuthController
 * @package App\Controller
 */
class DashboardController extends AbstractController
{
    protected $red;
    /**
     * @RequestMapping(path="test",methods="get")
     * @return ResponseInterface
     */
    public function index(): ResponseInterface
    {
        $config = [
            'app_id' => 'wxb333b63a53294790',
            'secret' => '7811a3be3c42d5cfab242af254b30614',
            'response_type' => 'array',
        ];

        $app = Factory::officialAccount($config);

        $app['guzzle_handler'] = CoroutineHandler::class;

        $app['cache'] = ApplicationContext::getContainer()->get(CacheInterface::class);

        $message = "😂医疗险为报销型，重疾险是给付型；\n😂医疗险最高保额为600万，重疾险最高保额为50万；\n😂医疗险被保人首次投保年龄最高为60周岁（含），重疾险被保人首次投保年龄最高为65周岁（含）；您可能也想看看（请点击）\n☞<a href='weixin://bizmsgmenu?msgmenucontent=这款产品有没有病种的限制？&msgmenuid=1'> 这款产品有没有病种的限制？</a>\n☞<a href='weixin://bizmsgmenu?msgmenucontent=有什么保险&msgmenuid=2'> 有什么保险</a>\n☞<a href='weixin://bizmsgmenu?msgmenucontent=人寿保险和这个冲突吗&msgmenuid=3'> 人寿保险和这个冲突吗</a>";

//        $text =  $app->server->push(function () use ($message) {
//            return new Text($message);
//        });
       ;


//        $list = $app->menu->list();

//        $list = $app->media->uploadImage('https://img2.baidu.com/it/u=2093840189,3436808924&fm=26&fmt=auto');
//          $list = $app->user->list();
//        return $this->success($list);
//        $list = $app->menu->create([
//            'name' => '测试菜单',
//            'type' => 'view',
//            'url' => 'http://hf.imhsc.cn'
//        ]);

        $res = $app->customer_service->message($message)
        ->to('oBSuM56mrUQ3KlRflm_urVijO8dY')
        ->send();

        return $this->success($res);
    }

    /**
     * @RequestMapping(path="my",methods="get")
     * @return ResponseInterface
     */
    public function my(){
        $userInfo = $this->getUserInfo();
        return $this->success($userInfo);
    }

    /**
     * @RequestMapping(path="auth-menus",methods="get")
     * @return ResponseInterface
     */
    public function authMenuList(): ResponseInterface
    {
        $userInfo = $this->getUserInfo();

        $menuList = $this->container->get(SystemPermission::class)->getPermissionsByRoleIds($userInfo['role_ids'],$userInfo['id']);

        return $this->success($menuList);
    }

}
